package com.kevin.chat.data;

import com.kevin.chat.entity.UserEntity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/*
 * 存放用户数据容器
 * @author Kevin
 * @date 2021/1/13 17:49
 *
 */
public class UserData {
    private static Map<String, UserEntity> userMap = new HashMap<>();
    static {
        initData();
    }

    //初始化数据
    private static void initData() {
        System.out.println("数据初始化  initData()............");
        UserEntity kevinUser = new UserEntity(1000, "Kevin", "Kevin", "Kevin");
        UserEntity caolgUser = new UserEntity(2000, "caolg", "曹刚", "刚哥");

        List<UserEntity> kevinFriendList = new ArrayList<>();
        UserEntity fUser1=new UserEntity(2000, "caolg", "曹刚", "刚哥");
        kevinFriendList.add(fUser1);

        List<UserEntity> caolgFriendList = new ArrayList<>();
        fUser1=new UserEntity(1000, "Kevin", "Kevin", "Kevin");
        caolgFriendList.add(kevinUser);

        kevinUser.setFriendList(kevinFriendList);
        caolgUser.setFriendList(caolgFriendList);

        userMap.put("Kevin", kevinUser);
        userMap.put("caolg", caolgUser);
    }



    public static UserEntity get(String key) {
        return userMap.get(key);
    }

    public static void put(UserEntity user) {
        userMap.put(user.getLoginName(), user);
    }

    public static void main(String[] args) {
    }
}
